export default {
    data() {
        return {
            tableData: [],
            date: '',
            title: '',
            sn: '',
            subtitle: '',
            picture: '',
            cost_price: '',
            labels: [],
            content: '',
            trip_list: [],
            crowd_notice: '',
            use_mode: '',
            matter_con: '',
            cost_contain: '',
            cost_exclusive: '',
            price_list: [],
            not_pass_show: false,
            reason: '',
            is_audit: 0
        }
    },
    //进入页面加载
    mounted: function () {
        var that = this;
        //在缓存中获取值
        that.user_name = sessionStorage.getItem("user_name");
        that.user_id = sessionStorage.getItem("user_id");
        that.token = sessionStorage.getItem("access-token");
        if ((!that.token) || (!that.user_id) || (!that.user_name)) {
            that.$router.push('/login');
        }
        if (that.$route.query.goods_id) {
            that.goods_id = that.$route.query.goods_id;
            that.getDetail();
        }

    },

    //方法
    methods: {

        /**
         * 列表
         */
        getDetail() {
            var that = this;
            that.tableData = [];
            //请求的数据
            var formData = {};
            formData.token = that.token;
            formData.goods_id = that.goods_id;
            //请求邀请者列表
            that.$http.post(that.adminApi.api_url + "/Publics/preview", formData, {
                emulateJSON: true
            }).then(
                function (res) {
                    // 处理成功的结果
                    if (res.body) {
                        if (res.body.traffic) {
                            for (var i in res.body.traffic) {
                                that.tableData.push({
                                    i: i,
                                    id: res.body.traffic[i].id,
                                    go_date: res.body.traffic[i].go_date,
                                    place: res.body.traffic[i].place,
                                    flight: res.body.traffic[i].flight,
                                    go_place: res.body.traffic[i].go_place,
                                    go_time: res.body.traffic[i].go_time,
                                    return_time: res.body.traffic[i].return_time,
                                    return_place: res.body.traffic[i].return_place,
                                });
                            }
                        }
                        if (res.body.traffic) {
                            for (var i in res.body.price) {
                                if (res.body.price[i].is_children === 1) {
                                    var text = '是';
                                    var children_count = res.body.price[i].children_count;
                                    var children_price = res.body.price[i].children_price
                                } else {
                                    var text = '--';
                                    var children_count = '--';
                                    var children_price = '--';
                                }
                                if (res.body.price[i].room_price === 0) {
                                    var room_price = '--'
                                } else {
                                    var room_price = res.body.price[i].room_price
                                }

                                that.price_list.push({
                                    i: i,
                                    date: res.body.price[i].time,
                                    adult_price: res.body.price[i].adult_price,
                                    adult_count: res.body.price[i].adult_count,
                                    is_children: text,
                                    children_price: children_price,
                                    children_count: children_count,
                                    room_price: room_price,
                                });
                            }
                        }
                        that.title = res.body.title;
                        that.subtitle = res.body.subtitle;
                        that.sn = res.body.sn;
                        that.picture = res.body.picture;
                        that.cost_price = res.body.cost_price;
                        that.labels = res.body.labels;
                        that.content = res.body.content;
                        that.trip_list = res.body.scheduling;
                        that.crowd_notice = res.body.crowd_notice;
                        that.use_mode = res.body.use_mode;
                        that.matter_con = res.body.matter_con;
                        that.cost_contain = res.body.cost_contain;
                        that.cost_exclusive = res.body.cost_exclusive;
                        that.is_audit = res.body.is_audit;
                    }
                },
                function () {
                    // 处理失败的结果
                    that.$message({
                        type: 'error',
                        message: `操作提示: ${ '处理异常' }`
                    });
                });
        },


        /**
         * 时间转换
         * @param date
         * @returns {string}
         */
        formatDateTime: function (date) {
            var y = date.getFullYear();
            var m = date.getMonth() + 1;
            m = m < 10 ? ('0' + m) : m;
            var d = date.getDate();
            d = d < 10 ? ('0' + d) : d;
            var h = date.getHours();
            var minute = date.getMinutes();
            minute = minute < 10 ? ('0' + minute) : minute;
            return y + '-' + m + '-' + d;
        },

        /**
         * 跳转预览
         */
        toPreview() {
            this.$router.push('/flashover/preview')
        },
        /**
         * 返回上一页
         */
        back: function () {
            this.$router.go(-1)
        },

        /**
         * 审核通过
         */
        pass: function (e) {
            const that = this;
            that.$confirm('您确认审核通过该商品吗?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'success'
            }).then(() => {
                //请求登陆接口
                that.$http.post(that.adminApi.api_url + "/Publics/adoptFailed", {
                    token: that.token,
                    goods_id: that.goods_id
                }, {
                    emulateJSON: true
                }).then(
                    function (res) {
                        // 处理成功的结果
                        that.$message({
                            type: 'success',
                            message: `操作提示: ${ '操作成功' }`
                        });
                        that.back();
                    },
                    function () {
                        // 处理失败的结果
                        that.$message({
                            type: 'error',
                            message: `操作提示: ${ '处理异常' }`
                        });
                    });
            })
        },

        /**
         * 隐藏弹窗
         */
        hideReason: function () {
            const that = this;
            that.not_pass_show = false;
        },

        /**
         * 审核不通过
         */
        sendReason: function () {
            const that = this;
            //请求登陆接口
            that.$http.post(that.adminApi.api_url + "/Publics/auditFailed", {
                token: that.token,
                goods_id: that.goods_id,
                reason: that.reason
            }, {
                emulateJSON: true
            }).then(
                function (res) {
                    // 处理成功的结果
                    that.$message({
                        type: 'success',
                        message: `操作提示: ${ '操作成功' }`
                    });
                    that.back();
                },
                function () {
                    // 处理失败的结果
                    that.$message({
                        type: 'error',
                        message: `操作提示: ${ '处理异常' }`
                    });
                });
        }
    }
}

